package com.zhangfei.stream;

import java.util.Arrays;
import java.util.List;

public class ReduceTest {
    public static void main(String[] args) {
        List<Student> students = Arrays.asList(
                new Student(1, "张三", 20),
                new Student(2, "李四", 22),
                new Student(3, "王五", 24)
        );

        int totalAge = students.stream()
                .mapToInt(Student::getAge)
                .reduce(0, Integer::sum);

        System.out.println("学生年龄总和：" + totalAge);
    }
}
